const mqtt = require('mqtt')

const client  = mqtt.connect('mqtt://127.0.0.1:1883')
 
client.on('connect', function () {
  client.subscribe('presence')
})
 
client.on('message', function (topic, message) {
  console.log(message.toString())
})

setInterval(() => {
  client.publish('presence', 'Hello mqtt')
}, 1500)

process.on('exit', (code) => {

  console.log('MQTT DISCONNECT')  
  client.end()

})


